#include "syscall-init.h" 
#include "../fs/fs.h"
#include "../userprog/fork.h"

#define syscall_nr 32
typedef void* syscall;
syscall syscall_table[syscall_nr];

/* 返回当前任务的pid */
uint32_t sys_getpid(void){
    return running_thread()->pid;
}

// /* 打印字符串 str (未实现文件系统前的版本) */
// uint32_t sys_write(char* str){
//     console_put_str(str);
//     return strlen(str);
// }

/* 初始化系统调用 */
void syscall_init(void){
    put_str("syscall_init start\n");
    syscall_table[SYS_GETPID]   =   sys_getpid;
    syscall_table[SYS_WRITE]    =   sys_write;
    syscall_table[SYS_READ]    =    sys_read;
    syscall_table[SYS_MALLOC]   =   sys_malloc; //方法在 memory.c 中
    syscall_table[SYS_FREE]     =   sys_free;   //方法在 memory.c 中
    syscall_table[SYS_FORK]     =   sys_fork; 

    put_str("syscall_init done\n");
}